app.service('shopTechnicianService',['$q','utilService',function($q,utilService){

    //查找该技师信息
    this.findInfo= function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'shop/technician/id',
            params:{technicianId:$scope.shopTechnicianVO.id}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            deferred.reject("连接服务器出错！");
        })

        return deferred.promise;
    };

    //添加技师
    this.addTechnician=function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain+"/shop/technician/add",
            data:$scope.shopTechnicianVO,
            method:'POST'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    };

    //修改技师
    this.edit=function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain+"/shop/technician/edit",
            data:$scope.shopTechnicianVO,
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    };

    //查询技师负责的服务
    this.findById= function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'serve/technician/id',
            params:{technicianId:$scope.id}
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            deferred.reject("连接服务器出错！");
        });

        return deferred.promise;
    };

    //删除技师
    this.del=function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'shop/technician/del',
            data:{technicianId:$scope.technicianId.id},
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    };

    //删除图片
    this.delFrontImage=function($scope,url){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain+"/shop/technician/del/img",
            data:{picture:url,technicianId:$scope.shopTechnicianVO.id},
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });
        return deferred.promise;
    }
}]);